package com.honey.mamabike.user.entity;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by setsun on 2017/10/26.
 */
@Data
public class UserElement {

    private  Long userId;

    private String mobile;

    private  String token;

    private String platform;

    private String pushUserId;

    private String pushChannelId;


    public Map<String, String> toMap(){
        Map<String ,String > map = new HashMap<>();
        map.put("platform",this.platform);
        map.put("userId",this.userId+"");
        map.put("token",this.token);
        map.put("mobile",this.mobile);
        if (this.pushUserId != null){
            map.put("pushUserId",this.pushUserId);
        }
        if (this.pushChannelId != null){
            map.put("pushChannelId",this.pushChannelId);
        }
        return map;
    }

    /**
     * 转对象
     * @param map
     * @return
     */
    public static  UserElement fromMap(Map<String,String> map){
        UserElement ue = new UserElement();
        ue.setPlatform(map.get("platform"));
        ue.setToken(map.get("token"));
        ue.setMobile(map.get("mobile"));
        ue.setUserId(Long.parseLong(map.get("userId")));
        ue.setPushUserId(map.get("pushUserId"));
        ue.setPushChannelId(map.get("pushChannelId"));
        return ue;
    }


}
